//
//  LRPresentationController.swift
//  LRWeibo
//
//  Created by 雷路荣 on 15/12/31.
//  Copyright © 2015年 leilurong. All rights reserved.
//

import UIKit
//通知名字
let LRPresentationControllerDismissNotification = "LRPresentationControllerDismissNotification"

class LRPresentationController: UIPresentationController {
    
    ///容器视图将要布局
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        print(__FUNCTION__)
        //设置背景view
        containerView?.addSubview(backgView)
        backgView.ff_Fill(containerView!)
        containerView?.sendSubviewToBack(backgView)//最底部
        
        let modalView = presentedView()
        modalView?.frame = CGRectMake(100, 58, 200, 300)
    }
    ///自定义转场动画
    override func presentationTransitionWillBegin() {
        super.presentationTransitionWillBegin()
        print(__FUNCTION__)
        
    }
    ///背景视图点击
    func backgViewClick() {
        print(__FUNCTION__)
        //获取modal出来的控制器退出
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
        //让标题按钮转回去,用通知
        NSNotificationCenter.defaultCenter().postNotificationName(LRPresentationControllerDismissNotification, object: nil)
        
    }
    //MARK: -懒加载
    ///灰色背景
    private lazy var backgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.3, alpha: 0.2)
        //创建点击手势
        let tap = UITapGestureRecognizer(target: self, action: "backgViewClick")
        //添加给背景视图
        view.addGestureRecognizer(tap)
        return view
    }()
}



































